package rpg.client.player.swing.create;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import rpg.client.model.Actor;
import rpg.client.model.Actor.Gender;
import rpg.client.player.swing.TopContainer;
import rpg.util.Strings;

public class CreateCharacterJPanel extends JPanel implements ActionListener {
    private final TopContainer topContainer;

    private final JButton btnDone = new JButton("Create");
    private final JTextField tfName = new JTextField("Jayden");

    public CreateCharacterJPanel(TopContainer top) {
        super(new GridBagLayout());

        topContainer = top;

        GridBagConstraints gbc = null;
        gbc = new GridBagConstraints();
        add(new JLabel("Name:"), gbc);

        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        add(tfName, gbc);

        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 1;
        add(btnDone, gbc);

        btnDone.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        Actor.Builder ab = new Actor.Builder();
        ab.gender(Gender.MALE);
        ab.hairColour(Color.BLACK);
        ab.name(Strings.trim(tfName.getText()));
        topContainer.awtSubmitPlayer(ab);
    }
}
